package com.source.codemap.analyze;

import cn.hutool.json.JSONUtil;
import com.github.javaparser.JavaParser;
import com.github.javaparser.ParseResult;
import com.github.javaparser.ast.CompilationUnit;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Optional;

/**
 * @author wangchangjie
 * @date 2025/1/14 17:17
 */
public class ClassInfoAnalyzer {


    public static Optional<CompilationUnit> analyze(String filePath) {
        try (FileInputStream fileInputStream = new FileInputStream(filePath)) {
            JavaParser parser = new JavaParser();
            ParseResult<CompilationUnit> parse = parser.parse(fileInputStream);
            CompilationUnit compilationUnit = parse.getResult().orElseThrow(() -> new RuntimeException("Parsing error"));
            return Optional.of(compilationUnit);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Optional.empty();
    }


}
